<script setup>
import api from "./api.js";
import EditDialog from "./edit.vue";


const tableData = ref([])
const paging = reactive({
  total: 1,
  pageNum: 1,
  pageSize: 10,
})
const tableRef = ref()
const editDialog = ref();

function handleAdd() {
  editDialog.value.open();
}

function handleUpdate(row) {
  editDialog.value.open(row);
}

function getList() {
  api.list().then(response => {
    tableData.value = response.data;
  }).catch(error => {
    console.log(error);
  });
}

onMounted(()=> {
  getList();
})

</script>

<template>
  <div class="organization-structure-main" style="height: 100%;display: flex;flex-direction: column;">

    <div style="margin-bottom: 15px;">
      <el-button  @click="handleAdd">增加</el-button>
    </div>
    <vxe-table style="height: 100%;flex-grow: 1;"
        border="full"
        ref="tableRef" :tree-config="{transform: true, rowField: 'menuId', parentField: 'parentId'}"
               :row-config="{isCurrent: true, isHover: true}"
        :column-config="{resizable: true}"
        :data="tableData">
      <vxe-column field="menuName" title="名称" tree-node></vxe-column>
      <vxe-column field="orderNum" title="显示顺序"></vxe-column>
      <vxe-column field="path" title="路由地址"></vxe-column>
      <vxe-column width="250" title="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template #default="{ row }">
          <el-button size="small" link type="primary" @click="handleUpdate(row)">修改</el-button>
        </template>
      </vxe-column>
    </vxe-table>

    <EditDialog ref="editDialog" @sub="getList"></EditDialog>

  </div>
</template>

<style scoped lang="scss">
  .organization-structure-main {
    box-sizing: border-box;
    padding: 15px;
  }
</style>